"use strict";
/* Controllers */
app.controller("xinghuoReportAddController", ['$scope', '$location', '$rootScope', '$routeParams', 'xinghuoReportAddService', function ($scope, $location, $rootScope, $routeParams, xinghuoReportAddService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.p.id = $routeParams.id; // 如果id!=0为更新
    vm.p.dashboardType = 'report';

    var errorFn = function (result) {
        alert(result);
    };

    $scope.addDashboard = function () {
        var vm = $scope.vm;
        var params = vm.p;
        var procFn = function (response) {
            if (response.success && response.data) {
                alert("执行成功！")
            } else {
                alert(response.msg);
            }
        };
        xinghuoReportAddService.addDashboard(params, procFn, errorFn);
    };

    $scope.getDashboard = function () {
        var vm = $scope.vm;
        var params = {
            id: vm.p.id
        };
        var procFn = function (res) {
            if (res.success && res.data) {
                vm.p = res.data;
            } else {
                alert(res.msg);
            }
        };
        xinghuoReportAddService.getDashboard(params, procFn, errorFn);
    };
    if(vm.p.id!=0) {
        console.log(vm.p.id);
        $scope.getDashboard();
    }
}]);


/* Services */
app.service('xinghuoReportAddService', ['ajaxService', function (ajaxService) {

    this.addDashboard = function (tickets, successFunction, errorFunction) {
        ajaxService.AjaxPost(tickets, "/star/api/basic-service/v1/dashboard/addDashboard.do", successFunction, errorFunction);
    };

    this.getDashboard = function (tickets, successFunction, errorFunction) {
        ajaxService.AjaxPost(tickets, "/star/api/basic-service/v1/dashboard/getDashboard.do", successFunction, errorFunction);
    };

}]);

